<?php

namespace App\Models\Common;

use App\Models\BaseModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationExamineLogModel;
use App\Models\Wanggui\CustomerDepartmentTaskModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class MapNationalUniversitiesModel extends BaseModel
{
    use HasFactory;

    protected $table = "map_national_universities";

    protected $fillable = [
        'status'
    ];

    protected $appends = [
        'nameText',
        'lng'
    ];

    public function logRel(): HasMany
    {
        return $this->hasMany(OpenShopSiteLocationExamineLogModel::class, 'orderNo', 'wgNumber');
    }


    public function resourceWithMapRel()
    {
        return $this->hasOne(ResourcesModel::class, 'name', 'wgNumber')->where('module', ResourcesModel::MODULE_TYPE_WG_AUDIT)->where('business', ResourcesModel::BUSINESS_WG_AUDIT);
    }

    /**
     * 定义一个访问器
     */
    public function getNameTextAttribute()
    {
        return $this->name;
    }

    /**
     * 定义一个访问器
     */
    public function getLngAttribute()
    {
        return $this->lon;
    }


    /**
     * 关联大客户部选址任务
     * @return HasOne
     */
    public function siteTaskRel(): HasOne
    {
        return $this->hasOne(CustomerDepartmentTaskModel::class, 'wgNumber', 'wgNumber');
    }
}
